//
//  DataManager.m
//  MUBATE
//
//  Created by sunbin on 2017/2/15.
//  Copyright © 2017年 Quanli. All rights reserved.
//

#import "DataManager.h"

@implementation DataManager
- (instancetype)init
{
    self = [super init];
    if (self) {
        _jsonDic = [[NSMutableDictionary alloc]init];
    }
    return self;
}

+ (id)sharedManager {
    static dispatch_once_t once;
    static id instance;
    dispatch_once(&once, ^{
        instance = [self new];
    });
    return instance;
}

- (void)startAsyncRequest:(NSArray *)urlArray modelsArray:(NSArray *)modelsArray parameterAry:(NSArray *)parameterAry refreshHeadler:(void (^)(int index))refresh completionHeadler:(void (^) (int index))completion{
    
    for (int i = 0; i < urlArray.count; i++) {
        [ZL_NetworkHelper POST:urlArray[i] parameters:parameterAry[i] success:^(id responseObject) {
            NSDictionary *dic = (NSDictionary *)responseObject;
            
            NSString *res = IF_NULL_TO_STRING([dic objectForKey:@"res"]);
            NSString *msg = IF_NULL_TO_STRING([dic objectForKey:@"msg"]);
            if ([res isEqualToString:@"1"]) {
                NSString *modelStr = modelsArray[i];
                id modelObj = [NSClassFromString(modelStr) modelObjectWithDictionary:dic];
                [_jsonDic setObject:modelObj forKey:@(i)];
                refresh(i);
            }else{}
        } failure:^(NSError *error) {
            
        }];}
}



@end
